package com.own.business.system.menu.entity.vo;

import com.own.business.system.menu.entity.map.SystemRolePermissionMapVo;
import com.own.business.system.menu.entity.po.SystemRole;
import com.own.component.common.base.entity.vo.BaseVo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * SystemRoleVo
 *
 * @author chenxueli
 * @date 2024-03-31 09:22:58
 */
@Schema(title = "系统角色" + ConstantBeanSuffix.VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class SystemRoleVo extends BaseVo<SystemRole> implements Serializable {

    @Schema(title = "角色名称")
    private String name;

    @Schema(title = "客户端id")
    private String clientId;

    @Schema(title = "是否禁用 1=禁用 0=可用")
    private Integer isDisable;

    @Schema(title = "权限列表")
    private List<SystemRolePermissionMapVo> permissions;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public SystemRoleVo(@NonNull SystemRole entity) {
        super(entity);
        this.name = entity.getName();
        this.clientId = entity.getClientId();
        this.isDisable = entity.getIsDisable();
    }

    /**
     * 转po对象
     *
     * @param entity 原对象
     * @return po对象
     */
    @Override
    public SystemRole toPo(SystemRole entity) {
        if (entity == null) {
            entity = new SystemRole();
        }
        entity.setName(this.name);
        entity.setClientId(this.clientId);
        entity.setIsDisable(this.isDisable);
        return super.toPo(entity);
    }

}
